home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 25
/
Cream of the Crop 25.iso
/
bbs
/
doorinfo.zip
/
TLCFDEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-14
|
6KB
|
237 lines
/*
** This is a small demonstration of a multi-player door for Falken.
** This program is loaded by the 'loadtlcf.exe' door. See the source
** code for that program as well.
**
** This sample code implements a tiny teleconference under Falken.
** Everything you type is sent to the other players in the door.
** If you type '.exit' then you leave.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "doorutil.h"
int intlcf[65]; /* 65 is the maximum number of lines for
* Falken */
struct msg1 tlcfm1; /* structure used to receive messages from
* Falken */
char welcome_msg[]=
"This is a teleconference demo.\r"
"Whatever you type is sent to other people in the door.\r"
"Type .exit to leave.\r";
void tlcf_exit(int who)
{
int j;
intlcf[who] = 0; /* he is no longer here. */
/*
** tell the gang that he is gone!
*/
for (j = 0; j < numlines; j++)
{
if (intlcf[j])
{
qnprintf(j, "%s has left TLCFDEMO.\r",
acct[who].acctname);
}
}
/*
** last thing to do - get his loadtlcf door running again.
** the next instruction it executes should be an exit(), to
** get him back to the Falken menu.
*/
wakeup(user[who].u_doortcb);
}
void p_tlcf(int who)
{
int j;
if (strcmpi(".exit", tlcfm1.text) == 0)
{
tlcf_exit(who);
}
else
{
/*
** tell the gang what he typed!
*/
for (j = 0; j < numlines; j++)
{
if (intlcf[j])
{
qnprintf(j, "From %s : %s\r",
acct[who].acctname, tlcfm1.text);
}
}
}
}
main()
{
int j, k, n, m;
int playercount;
/*
** Basic initialization for a Falken door.
*/
init();
/*
** Special initialization for a multi-player door.
**
** This single task will handle multiple players. It will be loaded
** by the 'loadtlcf' door. The 'loadtlcf' door will have checked to
** see if a copy of this program was active already, but there is
** still a possibility that 2 copies can be loaded, if the 'loadtlcf'
** doors are run very close together.
**
** So... use the hog() function to prevent any other tasks from
** running while we check to see if another copy is already active.
*/
hog(); /* we need to stop multitasking momentarily */
if (check_tcb_names("tlcfdemo") == 1)
{
/*
** if check_tcb_names() returns a 1, a task with this name exists.
** the nohog() is not really necessary, but it is good practice to
** make sure that a nohog() is called after every hog()
*/
nohog();
exit(0);
}
/*
** If we get here, by falling through the check_tcb_names() check,
** then there are no active tasks with the name "tlcfdemo".
** Set our name to that value, so that any other tlcfdemo programs
** that start up will not find it, and exit gracefully.
*/
set_tcb_name("tlcfdemo");
/*
** It is now safe to let other tasks execute again.
*/
nohog();
/*
** the 'intlcf' array of flags is used internally to mark the lines
** that we know are already in the game.
*/
for (j = 0; j < 65; j++)
intlcf[j] = 0; /* nobody here yet */
/*
** Now a forever loop.
**
** We recognize a player has entered this program when the following
** conditions are true :
** - the u_stat variable in his/her user structure is 6 (in doors).
** - the doors_id is set the string 'tlcfdemo'.
**
** We must look at each line on the system, and if the above criteria
** are met, we must check the message queue for that line to see if
** there is text or a termination event for us to handle.
**
** The playercount variable is used to find out how many users are
** actually in the tlcfdemo door. It simply counts how many matches
** of the above criteria we get on each pass through the active lines.
*/
for (;;)
{
playercount = 0; /* set to 0 */
/*
** Many of the doorutil routines use the global 'who' variable to
** decide which line to send an event for. We will use this global
** variable also.
*/
for (who = 0; who < numlines; who++)
{
if ((user[who].u_stat == 6) &&
(strcmpi(user[who].doors_id, "tlcfdemo") == 0))
{
playercount++; /* found a player! hallelujah */
/*
** We have found a user who meets the criteria for being in tlcfdemo.
** If the 'intlcf' flag is not set, then this is the FIRST TIME that he
** has met this critereia, so send him a nice welcome message.
*/
if (intlcf[who] == 0) /* a new player! */
{
send(welcome_msg);
intlcf[who] = 1; /* no longer new */
}
/*
** Let's see if there are any events waiting on the input queue for
** this user. It is our responsibility to handle these messages,
** since he has joined our game!
*/
if (testmsg(user[who].door_inq) > 0)
{
/*
** testmsg() returns a positive number if a message is waiting.
** recvmsg() reads the first message from the queue.
*/
recvmsg(user[who].door_inq, &tlcfm1, 1100);
if (tlcfm1.type == 8)
{
/*
** message type 8 is an exit code from Falken. The guy probably
** dropped carrier
*/
tlcf_exit(who);
}
else if (tlcfm1.type == 1)
{
/*
** message type 1 is a normal text string entered by the user.
*/
p_tlcf(who);
}
}
}
/*
** the else referred to here is 'else the user is not in tlcfdemo'.
** If the guy is not in our door, but the intlcf flag says he is,
** then he has somehow exited the door without our knowledge.
** handle the cleanup involved with the guy leaving.
*/
else if (intlcf[who] != 0)
{
tlcf_exit(who); /* we think he's online, but he's not */
}
}
/*
** If playercount is 0, then we went through all the lines without finding
** a user in our game. Time to leave.
*/
if (playercount == 0)
{
(0);
}
/*
** We handled all the lines, and there is still more to do.
** the relinq() call is used to allow other doors to run.
** It is not necessary, but it does keep us from looping while
** we look at empty queues, which is a great waste of time.
*/
relinq();
} /* end for(;;) */
}